package com.android.phoenix.util;

import java.io.File;

import android.os.Environment;

/**
 * @ClassName: SDCardFileUtils
 * @Description: SD卡工具类
 * @author: SDCardFileUtils
 * @date: 2015-1-18 下午4:48:54
 */
public class SDCardFileUtils {

	/**
	 * @Title: avaiableSDCard
	 * @Description:SD卡是否可用
	 * @author: WanChao
	 * @date: 2015-1-18 下午4:49:29
	 * @return
	 */
	public static boolean isAvaiableSDCard() {
		String status = Environment.getExternalStorageState();
		if (status.equals(Environment.MEDIA_MOUNTED)) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * @Title: getSDCardRoot
	 * @Description: 获取SD卡根路径文件夹对象
	 * @author: WanChao
	 * @date: 2015-1-18 下午4:50:53
	 * @return
	 */
	public static File getSDCardRoot() {
		if (isAvaiableSDCard()) {
			return Environment.getExternalStorageDirectory();
		}
		return null;
	}

	/**
	 * @Title: getSDCardRoot
	 * @Description: 获取SD卡根路径
	 * @author: WanChao
	 * @date: 2015-1-18 下午4:50:53
	 * @return
	 */
	public static String getSDCardRootPath() {
		if (isAvaiableSDCard()) {
			return getSDCardRoot().getPath();
		}
		return null;
	}

	/**
	 * @Title: createFolder
	 * @Description: 创建文件夹
	 * @author: WanChao
	 * @date: 2015-1-18 下午4:59:32
	 * @param path
	 * @param folderName
	 * @return
	 */
	public static String createFolder(String path, String folderName) {
		if (isAvaiableSDCard()) {
			File dir = getSDCardRoot();
			String root = dir.getPath() + path + "/";
			dir = new File(root, folderName);
			if (!dir.exists()) {
				dir.mkdirs();
			}
			return dir.getAbsolutePath();
		}
		return null;
	}
}
